package org.example.basic.day05;

public class Demo02throw {
    public static void main(String[] args) {
            Person person = new Person();
        try {
            person.setAge(-10);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("年龄不在合法范围内");
        }
    }
}

class Person{
    private int age;
    public void setAge(int age) throws Exception{
        if(age < 0 || age > 130){
            throw new RuntimeException();
        }
        this.age = age;
    }
}
